package com.example.administrator.daydayappmarket.personal.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.daydayappmarket.R;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by lenovo on 2016/12/30.
 */

public class PersonalAdapter extends BaseAdapter {

    private Context context;
    //    private Map<String, Integer> data;
    private List<String> names;
    private List<Integer> icons;

    public PersonalAdapter(Context context, List<String> names, List<Integer> icons) {
        this.context = context;
        this.names = names;
        this.icons = icons;
    }

    @Override
    public int getCount() {
        return icons != null ? icons.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return names.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_fragment_personal, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.itemFragmentPersonalTextView.setText(names.get(position));
        Glide.with(context).load(icons.get(position)).into(viewHolder.itemFragmentPersonalImageView);
        if(position==names.size()-1){
            viewHolder.itemFragmentPersonalView.setVisibility(View.GONE);
            viewHolder.itemFragmentPersonalJiantou.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }



    static class ViewHolder {
        @InjectView(R.id.item_fragment_personal_imageView)
        ImageView itemFragmentPersonalImageView;
        @InjectView(R.id.item_fragment_personal_textView)
        TextView itemFragmentPersonalTextView;
        @InjectView(R.id.item_fragment_personal_view)
        View itemFragmentPersonalView;
        @InjectView(R.id.item_fragment_personal_jiantou)
        View itemFragmentPersonalJiantou;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }


}
